using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline.Processors;

using VTESCore;

namespace VTESCustomContentPipeline
{
	/// <summary>
	/// This class will be instantiated by the XNA Framework Content Pipeline
	/// to apply custom processing to content data, converting an object of
	/// type TInput to TOutput. The input and output types may be the same if
	/// the processor wishes to alter data without changing its type.
	///
	/// This should be part of a Content Pipeline Extension Library project.
	///
	/// TODO: change the ContentProcessor attribute to specify the correct
	/// display name for this processor.
	/// </summary>
	[ContentProcessor( DisplayName = "VTESCustomContentPipeline.VTESDeckContentProcessor" )]
	public class VTESDeckContentProcessor : ContentProcessor<VTESDeck, VTESDeck>
	{
		public override VTESDeck Process( VTESDeck input, ContentProcessorContext context )
		{
			foreach(VTESCard card in input)
			{
				ExternalReference<TextureContent> texture = new ExternalReference<TextureContent>( context.IntermediateDirectory + "..\\..\\..\\cardimages" + card.CardArtPath );
				ExternalReference<TextureContent> built_texture = context.BuildAsset<TextureContent, TextureContent>( texture, "TextureProcessor" );

				// update the card art path to point to the built filename
				card.CardArtPath = Path.Combine( Path.GetDirectoryName( card.CardArtPath ), Path.GetFileName( built_texture.Filename ) );
			}

			return input;
		}
	}
}